import { requestClient } from '#/api/request'

import { downloadFileFromBlobPart } from '@vben/utils'

/**
 * 获取应付数据列表
 */
async function getMMeetIndex(params: any) {
  return requestClient.post('/admin/materialBatchBill/mMeetIndex', params)
}

/**
 * 获取供应商选项
 */
async function getSupplyOptions(params?: any) {
  return requestClient.get('/admin/supply/index', params)
}

/**
 * 获取商品分类选项
 */
async function getCategoryOptions(params?: any) {
  return requestClient.get('/admin/goodsCategory/allIndex', params)
}

/**
 * 获取时间分类选项
 */
async function getTimeCategoryOptions(params?: any) {
  return requestClient.get('/admin/goodsTimeCategory/allIndex', params)
}

/**
 * 导出数据
 */
async function exportMMeet(params: any) {
  const res = await requestClient.post('/admin/MaterialBatchBill/mMeetIndex', params, {
    responseType: 'blob',
    responseReturn: 'raw',
  })

  const blob = new Blob([res.data], {
    type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  })
  downloadFileFromBlobPart({
    source: blob,
    fileName: '物料（按月）应付数据.xlsx',
  })
}

export { getMMeetIndex, getSupplyOptions, getCategoryOptions, getTimeCategoryOptions, exportMMeet }
